package com.example.demo.gouzaoqi;


//适配器模式
public class AdaptModel {
    interface Duck {
        public  void quack();
        public  void fly();
    }

    public static class Lvtouya implements Duck {

        @Override
        public void quack() {
            System.out.println("quack");
        }

        @Override
        public void fly() {
            System.out.println("fly");
        }
    }

  interface Turkey {
        //咯咯叫
        public  void gobble();
        public  void fly();
    }

    public static class WildTyrkey implements Turkey {

       @Override
       public void gobble() {
           System.out.println("gobble");
       }

       @Override
       public void fly() {
           System.out.println("fly");
       }
   }

    //现在需要一个鸭子  但是只有火鸡对象，于是写一个火鸡适配器

    public static class TurkeyAdapt implements Duck{
        Turkey turkey;

      //这里需要一个构造器
        public  TurkeyAdapt(Turkey turkey){
            this.turkey=turkey;
        }

       @Override
        public void quack() {
            turkey.gobble();
        }

        @Override
        public void fly() {
            turkey.fly();
        }
    }



}
